home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / vaxinkey.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  4KB  |  229 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include "edt.h"
  6. #define true (!false)
  7. #define false 0
  8. int fner(char *s);
  9. int scr_refresh(void);
  10. int scr_getch(void);
  11. char *function_bar()
  12. {
  13.     return "F11-Help  F12-Save  F13-Load  F14-Save as        F9-Graph Form  F10-Drawit";
  14. }
  15.  
  16. struct escape_struct {char *str; int val;};
  17.  
  18. struct escape_struct gold[] = {
  19.         "v",     epaste,
  20.         "R",    esearch,
  21.         "S",    eundeleol,
  22.         NULL,    };
  23.  
  24. struct escape_struct eseq[] = {
  25.         "4~",     eselect,
  26.         "1~",    esearch,
  27.         "2~",    epaste,
  28.         "3~",    ecut,
  29.         "4~",    eselect,
  30.         "5~",    epageup,
  31.         "6~",    epagedown,
  32.         "A",    eup,
  33.         "B",    edown,
  34.         "C",    eright,
  35.         "D",    eleft,
  36.         "20~",    egraphmenu,
  37.         "21~",    edrawit,
  38.         "23~",    ehelp,
  39.         "24~",    esave,
  40.         "25~",    eload,
  41.         "26~",    esaveas,
  42.         "P",    egold,
  43.         "Q",    ehelp,
  44.         "R",    efindnext,
  45.         "S",    edeleol,
  46.         "n",    eselect,
  47.         "v",    ecut,
  48.         "r",    eeol,
  49.         "l",    edelright,
  50.         NULL,    };
  51.  
  52. int gold_fn[] = {
  53.     edrawit,ehelp,esave,eload,esaveas,eshowerror,0,0,0,egraphmenu,edrawit
  54. };
  55. struct keymatch {int m; int val;};
  56. /* Normal key and ^ commands  commands */
  57. struct keymatch kmatch2[] = {
  58.     13, ereturn,
  59.     3, equit,
  60.     4, eword,
  61.     5, eedt,
  62.     6, efast,
  63.     7, edrawit,
  64.     18, eshowerror,
  65.     8, ehelp,
  66.     20, etrace,
  67.     12, efindnext,
  68.     21, eundelline,
  69.     25, edelline,
  70.     26, eescape,
  71.     27, eescape,
  72.     127, edelete,
  73.     0,0
  74. };
  75. /* Control K commands */
  76. struct keymatch kmatch3[] = {
  77.     'b', eselect,
  78.     'v', emove,
  79.     'k', emark,
  80.     'c', ecopy,
  81.     'y', ecut,
  82.     'u', epaste,
  83.     'p', epaste,
  84.     'r', eblockread,
  85.     'w', eblockwrite,
  86.     'm', egraphmenu,
  87.     'l', eload,
  88.     'd', edrawit,
  89.     's', esave,
  90.     'x', equit,
  91.     0,0
  92. };
  93. /* Control Q commands */
  94. struct keymatch kmatch4[] = {
  95.     'f', esearch,
  96.     'c', eendoffile,
  97.     'r', etopoffile,
  98.     0,0
  99. };
  100.  
  101. text_inkey()
  102. {
  103.     int cc,i,c1,c2;
  104.  
  105.     scr_refresh();
  106.  
  107. loop1:    cc = tt_inkey();
  108.     c2 = (cc & 0xff);
  109.     switch(c2) {
  110.       default:
  111.         for (i=0;kmatch2[i].m!=0;i++)
  112.         if (kmatch2[i].m==c2) return kmatch2[i].val;
  113.         break;
  114.       case 27:
  115.         c2 = tt_inkey(); /* throw away next char (unless escape) */
  116.         if (c2==27) return eescape;
  117.       case -101:
  118.       case -113:
  119.         c2 = escape_seq();
  120.         if (c2==egold) {
  121.             c2 = tt_inkey();
  122.             if (c2==27) {
  123.                 tt_inkey();
  124.                 return escape_seq_gold();
  125.             } else if (isdigit(c2)) {
  126.                 return gold_fn[c2-'0'];
  127.             }
  128.         }
  129.         return c2;
  130.         break;
  131.       case 17:
  132.         fner("^Q  F=Find string,  R=Top of file");
  133.         cc = tt_inkey();
  134.         c2 = (cc & 0xff);
  135.         if (c2<32) c2 = c2 + 'a' - 1;
  136.         c2 = tolower(c2);
  137.         for (i=0;kmatch4[i].m!=0;i++)
  138.         if (kmatch4[i].m==c2) return kmatch4[i].val;
  139.         fner("Unrecognized Quick movement command");
  140.         goto loop1;
  141.       case 11:
  142.         fner("^K  B=begin block,  P=Paste,  (use KP6 for Cut),  K=End block");
  143.         cc = tt_inkey();
  144.         c2 = (cc & 0xff);
  145.         if (c2<32) c2 = c2 + 'a' - 1;
  146.         c2 = tolower(c2);
  147.         for (i=0;kmatch3[i].m!=0;i++)
  148.         if (kmatch3[i].m==c2) return kmatch3[i].val;
  149.         fner("Unrecognized block command");
  150.         goto loop1;
  151.     }
  152.     return c2;
  153. }
  154. escape_seq()
  155. {
  156.     int cc,i;
  157.     unsigned char esq[10];
  158.     char *s;
  159.  
  160.     s = &esq[0];
  161.     *s++ = cc = tt_inkey();
  162.     while (cc<65) *s++ = cc = tt_inkey();
  163.     *s++ = 0;
  164.     for (i=0;eseq[i].str!=NULL;i++)
  165.         if (strcmp(eseq[i].str,esq)==0) break;
  166.     if (eseq[i].str!=NULL)
  167.         return eseq[i].val;
  168.     else
  169.         return 0;
  170.  
  171. }
  172. escape_seq_gold()
  173. {
  174.     int cc,i;
  175.     unsigned char esq[10];
  176.     char *s;
  177.  
  178.     s = &esq[0];
  179.     *s++ = cc = tt_inkey();
  180.     while (cc<65) *s++ = cc = tt_inkey();
  181.     *s++ = 0;
  182.     for (i=0;gold[i].str!=NULL;i++)
  183.         if (strcmp(gold[i].str,esq)==0) break;
  184.     if (gold[i].str!=NULL)
  185.         return gold[i].val;
  186.     else
  187.         return 0;
  188.  
  189. }
  190.  
  191.  
  192. #include <descrip.h>
  193. #include <iodef.h>
  194. int tt_chan;
  195. short tt_iosb[4];
  196. int tt_inkey();
  197. key_open()
  198. {
  199.     int st;
  200.     static $DESCRIPTOR(tt_desc,"tt");
  201.     st = SYS$ASSIGN(&tt_desc,&tt_chan,0,0);
  202. }
  203. int tt_inkey()
  204. {
  205.     int read_mask,st;
  206.     unsigned char inbuff[9];
  207.     static int key_isopen;
  208.  
  209.     if (!key_isopen) {key_open(); key_isopen=true;}
  210.     read_mask = IO$_READLBLK | IO$M_NOFILTR | IO$M_NOECHO;
  211.     st = SYS$QIOW(0,tt_chan,read_mask,tt_iosb,0,0,inbuff,1,0,0,0,0);
  212.     if ((st & 1) != 1) LIB$SIGNAL(st);
  213.     if ((tt_iosb[0] & 1) != 1) LIB$SIGNAL(tt_iosb[0]);
  214.     return inbuff[0];
  215. }
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.